package com.fm.financemanage.controller;

import com.fm.financemanage.constant.ResponseEnum;
import com.fm.financemanage.model.po.AqConfig;
import com.fm.financemanage.model.po.User;
import com.fm.financemanage.model.vo.PageVo;
import com.fm.financemanage.model.vo.user.UserListVo;
import com.fm.financemanage.response.Callback;
import com.fm.financemanage.response.JsonData;
import com.fm.financemanage.service.AqConfigService;
import com.fm.financemanage.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RequestMapping("/aq")
@Api(tags = "问答配置信息")
@RestController
@Validated
public class AqConfigController {

    @Autowired
    private AqConfigService aqConfigService;


    @GetMapping("/")
    @ApiOperation("查询")
    public JsonData<PageVo<List<AqConfig>>> getList(HttpServletRequest request, HttpServletResponse response,
                                                    @ApiParam(name = "keyword", value = "关键词,", required = true)
                                                      @RequestParam(name = "keyword", required = false) String keyword,
                                                    @ApiParam(name = "page", value = "页码", required = true)
                                                      @RequestParam(name = "page", required = false) Integer page,
                                                    @ApiParam(name = "limit", value = "条数", required = true)
                                                      @RequestParam(name = "limit", required = false) Integer limit
    ) {


        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo(), aqConfigService.getList(keyword, page, limit));
    }


    @PostMapping("/")
    @ApiOperation("修改或新增")
    public JsonData operator(HttpServletRequest request, HttpServletResponse response,
                             @RequestBody AqConfig aqConfig
    ) {

        aqConfigService.operator(aqConfig);
        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo());
    }




    @DeleteMapping("/{id}")
    @ApiOperation("删除")
    public JsonData removeById(HttpServletRequest request, HttpServletResponse response,
                             @PathVariable("id") Integer id
    ) {

        aqConfigService.removeById(id);
        return Callback.success(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMemo());
    }
}
